// pages/payCartSuccess/payCartSuccess.js
import {
  HTTP
} from '../../utils/http.js'
import api from '../../utils/api.js'
import { config } from '../../utils/config'
const http = new HTTP()
const app = getApp();

Page({

    /**
     * 页面的初始数据
     */
    data: {
        // 此页面 页面内容距最顶部的距离
        height: app.globalData.height * 2 + 20,
        showGoPayBtn: true, //是否显示 继续支付的按钮
        selectGoods: [],
        imgUrl: config.imgUrl,
        products: [], //推荐的商品-单品
        num: 0
    },
    backMeuns(e) {
        console.log(e)
        wx.switchTab({
            url: '/pages/classify/classify',
            success: function(res) {
                //单品全部购买完成后，跳转时清除已购买单品id
                //在 单品分类 是否要清除一遍classify？？？？
                wx.removeStorageSync('alreadyShopId')
            }
        })

        //清空 缓存时间段
        wx.removeStorageSync('timeField1')
        wx.removeStorageSync('timeField2')
    },
    backShopList(e) {
        let alreadyShopId = wx.getStorageSync('alreadyShopId')
        let aaa = JSON.stringify(alreadyShopId)
        console.log('aaaaaaaa', aaa)
        wx.reLaunch({
            url: `/pages/recommendShopGoodList/recommendShopGoodList?alreadyShopId=${aaa}&type=2`
        })
    },
    /**
     * 生命周期函数--监听页面加载
     */
    onLoad: function(options) { 
        let order_no = options.order
        this.setData({
          order_no
        })
        let payList = wx.getStorageSync('payList');
        if(payList.length > 0){
          let noBuy = ''
          payList.forEach(item => {
            noBuy += (item.name + ' ')
          })
          this.setData({
            payList,
            noBuy
          })
        }


        // this.compareVegetables();


        // // 展示 推荐 商品
        // this._recommendProducts();
    },
    goDetail(){
      wx.navigateTo({
        url: '/pages/orderDetail/orderDetail?order='+this.data.order_no
      })
    },
    goBuy(){
      wx.navigateTo({
        url: '/pages/recommendShopList/recommendShopList'
      })
    },
    goOrderList(){
      wx.navigateTo({
        url: "/pages/myAllOrderList/myAllOrderList"
      })
    },
    backIndex(){
      wx.reLaunch({
        url:'/pages/index/index'
      })
    },
    // 购物添加的单品 与 已购买的 单品
    

  
    //跳转到单品菜篮
    goShoppingCar() {

        wx.switchTab({
            url: '/pages/shoppingCar/shoppingCar',

        })
    },
    /**
     * 生命周期函数--监听页面卸载
     */
    onUnload: function() {
        //清除已购买的单品
        wx.removeStorageSync('vegetaleCurrent')
    }
})